import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import { manualChunksPlugin } from 'vite-plugin-webpackchunkname';

function resolve(dir: string): string {
    return path.join(__dirname, dir);
}

const isProd = process.env.NODE_ENV === "production";

const useRemote = true;
const useHttps = useRemote ? false : false;
const proxyRemote = useRemote ? "hnxsst.ricebird.cn" : "localhost:7144"; // "127.0.0.1:7253" //

// https://vitejs.dev/config/
export default defineConfig({
    base: process.env.NODE_ENV === "production" ? "/manage/" : "/",
    plugins: [ vue() ],
    build: {
        target: ["edge90", "chrome90", "firefox90", "safari15"], // 2021年以后的浏览器均可使用
        minify: "terser",
        terserOptions: {
            compress: {
                drop_console: true,
                drop_debugger: true,
            },
        }
    },    
    css: {
        preprocessorOptions: {
            less: {
                charset: false,
                additionalData: '@import "@/assets/mixin.less";',
            },
        },
    },
    resolve: {
        alias: [
            {
                find: "@",
                replacement: resolve("src"),
            },
            {
                find: "@vc",
                replacement: resolve("src/cores"),
            },
            {
                find: "@vm",
                replacement: resolve("src/modules"),
            },
            {
                find: "@layouts",
                replacement: resolve("src/layouts"),
            }
        ],
    },
    server: {
        proxy: {
            "/api": {
                target: `${useHttps ? "https" : "http"}://${proxyRemote}`,
                changeOrigin: true,
                secure: false,
            },
            "/signalr": {
                target: `${useHttps ? "wss" : "ws"}://${proxyRemote}`,
                changeOrigin: true,
                ws: true,
                secure: false,
            },
            "/debug": {
                target: `${useHttps ? "https" : "http"}://${proxyRemote}`,
                changeOrigin: true,
                secure: false,
            },
            "/permanent": {
                target: `${useHttps ? "https" : "http"}://${proxyRemote}`,
                changeOrigin: true,
                secure: false,
            },
        },
    },
});
